package com.wwj.core.server.service.impl;

import com.wwj.core.server.entity.GameServer;
import com.wwj.core.server.entity.mapper.GameServerMapper;
import com.wwj.core.server.service.IGameServerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class GameServerServiceImpl implements IGameServerService {

    @Resource
    private GameServerMapper gameServerMapper;

    @Override
    public GameServer findByServerName(String serverName) throws Exception {
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("serverName", serverName);
        List<GameServer> list = gameServerMapper.selectByParam(param);
        return list != null && list.size() > 0 ? list.get(0) : null;
    }

    @Override
    public int createNewServer(GameServer server) throws Exception {
        server.setCreateTime(Calendar.getInstance().getTime());
        return gameServerMapper.save(server);
    }

    @Override
    public int updateServer(GameServer server) throws Exception {
        server.setUpdateTime(Calendar.getInstance().getTime());
        return gameServerMapper.update(server);
    }
}
